﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Tuzzit_Modele;
using ViewModel;

namespace Tuzzit
{
    public partial class UserSettings : PhoneApplicationPage
    {
        public UserSettings()
        {
            InitializeComponent();
            SettingUser.Text = AppResources.UserSettingsLittle;
            SettingTitle.Text = AppResources.UserSettingsTitle;
            Howto.Text = AppResources.UserSettingsHowto;
            AddMessage.Content = AppResources.UserSettingsAddMessage;
            ChampMsg.Text = AppResources.UserSettingsEnterText;
            ContenuListe.Text = AppResources.UserSettingsMessageContained;

            ListeDesMessages.DataContext = (Application.Current as App).Motd;      
        }

        private void AddMessage_Click(object sender, RoutedEventArgs e)
        {
            String MOTD = ChampMsg.Text;
            (Application.Current as App).Motd.MyItems.Add(new ModeleMessage(MOTD));
        }

        private void ItemToDelete(object sender, RoutedEventArgs e)
        {
            //ListeDesMessages.SelectedItem();
           // (Application.Current as App).Motd.MyItems.Remove((ModeleMessage)ListeDesMessages.SelectedItem);

             ModeleMessage itemSelected = (ModeleMessage)ListeDesMessages.SelectedItem;
             (Application.Current as App).Motd.MyItems.Remove(itemSelected);
              
        }

        private void ShowRandom(object sender, RoutedEventArgs e)
        { 
            //ne pas oulier de virer le bouton du XAML :)
            if ((Application.Current as App).Motd.MyItems.Count >0)
            {
                Random random = new Random();
                int randomNumber = random.Next(0, (Application.Current as App).Motd.MyItems.Count);
                ModeleMessage itemSelected =(Application.Current as App).Motd.MyItems.ElementAt(randomNumber);
                MessageBox.Show(itemSelected.MessageToAdd);
            }
        }
    }
}